﻿using System.Data;
using System;
namespace Reviewer.Utilities.Data
{
    public static class DataReaderUtil
    {
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="returnValueIfDbNull">The return value if db null.</param>
        /// <returns></returns>
        public static string GetValue(IDataReader reader, int ordinal, string returnValueIfDbNull)
        {
            return reader.IsDBNull(ordinal) ? returnValueIfDbNull : reader.GetString(ordinal);
        }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="returnValueIfDbNull">The return value if db null.</param>
        /// <returns></returns>
        public static Int32 GetValue(IDataReader reader, int ordinal, Int32 returnValueIfDbNull)
        {
            return reader.IsDBNull(ordinal) ? returnValueIfDbNull : reader.GetInt32(ordinal);
        }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="returnValueIfDbNull">The return value if db null.</param>
        /// <returns></returns>
        public static Boolean GetValue(IDataReader reader, int ordinal, bool returnValueIfDbNull)
        {
            return reader.IsDBNull(ordinal) ? returnValueIfDbNull : reader.GetBoolean(ordinal);
        }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="returnValueIfDbNull">The return value if db null.</param>
        /// <returns></returns>
        public static DateTime GetValue(IDataReader reader, int ordinal, DateTime returnValueIfDbNull)
        {
            return reader.IsDBNull(ordinal) ? returnValueIfDbNull : reader.GetDateTime(ordinal);
        }
    }
}